package com.example.hello;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.os.PersistableBundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends AppCompatActivity { //子类继承父类
    private static final String TAG = "MainActivity";
    int score1=0;
    int score2=0;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState); //调用父类方法
        setContentView(R.layout.activity_score);//设置当前容器视图内容，R：类（当前资源文件，R开头的都是），layout：类成员，属性
    }

    @Override
    protected void onSaveInstanceState(@NonNull Bundle outState) {
        super.onSaveInstanceState(outState);
        String teama=((TextView)findViewById(R.id.coA)).getText().toString();
        String teamb=((TextView)findViewById(R.id.coB)).getText().toString();
        outState.putString("teama_score",teama);
        outState.putString("teamb_score",teamb);
    }

    @Override
    protected void onRestoreInstanceState(@NonNull Bundle savedInstanceState) {
        super.onRestoreInstanceState(savedInstanceState);
        String teama=savedInstanceState.getString("teama_score");
        String teamb=savedInstanceState.getString("teamb_score");
        score1= Integer.parseInt(teama);
        showa();
        score2= Integer.parseInt(teamb);
        showb();

    }

    private void showa() {
        TextView show=findViewById(R.id.coA);
        show.setText(String.valueOf(score1));
    }
    private void showb() {
        TextView show=findViewById(R.id.coB);
        show.setText(String.valueOf(score2));
    }
    public void click_a(View v){
        if(v.getId()==R.id.a1){
            score1+=1;
            showa();
            RateManager manager=new RateManager(this);
            manager.findByName("aabb","11");
            /*RateItem item=new RateItem("aabb","11");
            manager.add(item);

             */
            List<RateItem> list=manager.listAll();
            for(RateItem item:list){
                Log.i(TAG,"myclick:item"+item);
            }


        }else if(v.getId()==R.id.a2){
            score1+=2;
            showa();
        }else{
            score1+=3;
            showa();
        }

    }

    public void click_b(View v){
        if(v.getId()==R.id.b1){
            score2+=1;
            showb();
        }else if(v.getId()==R.id.b2){
            score2+=2;
            showb();
        }else{
            score2+=3;
            showb();
        }

    }


    public void reset(View v){
        TextView show1=findViewById(R.id.coA);
        TextView show2=findViewById(R.id.coB);
        show1.setText("0");
        show2.setText("0");
    }

}